﻿namespace TopHero
{
    public class TickCounter : Singleton<TickCounter>
    {
        private float _interpolationTime = 0;
        private int _frameCount = 0;
        private float _elapseTime = 0;
        private float _timeScale = 1;

        public void Reset()
        {
            _frameCount = 0;
            _elapseTime = 0;
            _interpolationTime = 0;
            _timeScale = 1;
        }

        public void SetTimeScale(float timeScale)
        {
            _timeScale = timeScale;
        }

        public void Update(float deltaTime)
        {
            _elapseTime += deltaTime * _timeScale;
        }

        public void LaterUpdate()
        {
            _interpolationTime = _elapseTime - frameCount * GameDefine.DELTA_TIME;
        }

        public int frameCount => _frameCount;

        public float interpolationTime => _interpolationTime;

        public void AddFrameCount()
        {
            _frameCount++;
        }

        public int expectFrameCount => (int) (_elapseTime / GameDefine.DELTA_TIME);


        public float currentTime => frameCount * GameDefine.DELTA_TIME;

        public float deltaTime => GameDefine.DELTA_TIME;
    }
}